package project.product.internal;

import java.io.Serializable;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import project.product.Cloth;
import project.product.ClothService;

public class ClothServiceImpl extends HibernateDaoSupport  implements ClothService{

    @Override
    public Cloth getCloth(Serializable id) {
        StringBuffer queryString = new StringBuffer(" FROM Cloth where id=?");
        List<Cloth> list = this.getHibernateTemplate().find(queryString.toString(), id);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public List<Cloth> findByBrandId(Serializable brand_id) {
        StringBuffer queryString = new StringBuffer(" FROM Cloth where brand_id=? AND shelves = ? ORDER BY order");
        return this.getHibernateTemplate().find(queryString.toString(), new Object[]{brand_id,true});
    }

    @Override
    public void addPraise(String id) {
        Cloth cloth =  this.getCloth(id);
        if (cloth != null) {
            cloth.setPraise(cloth.getPraise() +1);
            this.getHibernateTemplate().update(cloth);
        }
        
    }

}
